import QtQuick
import QtQuick.Controls
import QtQuick.Effects
import "../component" as C

Item {
    Theme { id: theme }
    property variant modelDlg;
    FontLoader {
        id: iconFont
        source: "qrc:/assets/fontawesome-free-6.7.2-desktop/otfs/Font Awesome 6 Free-Solid-900.otf"
    }

    Rectangle {
        anchors.fill: parent
        color: "transparent"
    }
    function hideMask(){
        modelDlg.destroy();
    }
    Loader {
        id: weightSettingPage
        source: "qrc:/pages/RangeSettingPage.qml"
        onLoaded: {
            item.title= "称重设置"
            item.type="weight"
        }
    }
    Loader {
        id: weightCalibrationPage
        source: "qrc:/pages/WeightCalibrationPage.qml"
    }
    // 右上角：kg / cal / 参数设置 图片按钮
    Row {
        anchors.top: parent.top
        anchors.right: parent.right
        anchors.topMargin: 20
        anchors.rightMargin: 20
        spacing: 15

        C.ZButtonImage{
            btnImagePressed: "qrc:/assets/weight/cal_pressed.png"
            btnImage:"qrc:/assets/weight/cal.png"
            onClicked: {
                weightCalibrationPage.item.resetForm()
            }
        }
        C.ZButtonImage{
            btnImagePressed: "qrc:/assets/icon_settings_parameters_pressed.png"
            btnImage:"qrc:/assets/settings_parameters.png"
            onClicked: {
                var weightParam = alarmInfo.getWeightParam();
                console.log("weightParam", weightParam["hh"]);
                weightSettingPage.item.setValue(weightParam["hh"],
                                                weightParam["h"],
                                                weightParam["l"],
                                                weightParam["ll"],
                                                weightParam["hhStatus"],
                                                weightParam["hStatus"],
                                                weightParam["lStatus"],
                                                weightParam["llStatus"])
                weightSettingPage.item.visible = true;
            }
        }
    }


    // 中心称重
    Column {
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.verticalCenter: parent.verticalCenter
        spacing: 60

        // 主显示
        Item {
            width: 1020
            height: 340

            Image {
                id: mainBg
                anchors.fill: parent
                source: "qrc:/assets/weightbg.png"
                fillMode: Image.PreserveAspectFit
                smooth: true
            }

            Row {
                anchors.centerIn: parent
                spacing: 10
                Text {
                    id: weightText
                    text: collectionInfo.weight
                    font.pixelSize: 128
                    font.bold: true
                    color: "#2F3C4E"
                }
                Text {
                    text: "kg"
                    font.pixelSize: 54
                    color: "#6F7F90"
                    anchors.bottom: weightText.bottom
                    anchors.bottomMargin: 10
                }
            }

            // 皮重
            Item {
                id: tareCapsuleGroup
                width: 700
                height: 200
                anchors.horizontalCenter: parent.horizontalCenter
                anchors.top: parent.bottom
                anchors.topMargin: -105

                Image {
                    id: tareBg
                    anchors.fill: parent
                    source: "qrc:/assets/Controlsbgshort.png"
                    fillMode: Image.PreserveAspectFit
                    smooth: true
                }

                Row {
                    anchors.centerIn: parent
                    spacing: 68
                    Text { text: "皮重:"; font.pixelSize: 36; color: "#6F7F90" }
                    Text { id: tareText; text: "0.000"; font.pixelSize: 42 ; color: "#2F3C4E" }
                    Text { text: "kg"; font.pixelSize: 36; color: "#6F7F90" }
                }
            }
        }

        // 底部
        Row {
            spacing: 80
            anchors.horizontalCenter: parent.horizontalCenter

            // 归零按钮
            Item {
                width: 200; height: 200

                Image {
                    id: zeroBtn
                    anchors.centerIn: parent
                    anchors.verticalCenterOffset: 20
                    width: 200; height: 200
                    source: "qrc:/assets/button0.png"
                    smooth: true
                    property real baseScale: 1.0
                    scale: baseScale
                    Behavior on scale { NumberAnimation { duration: 120; easing.type: Easing.OutQuad } }
                    MouseArea {
                        anchors.fill: parent
                        onPressed: zeroBtn.baseScale = 0.92
                        onReleased: zeroBtn.baseScale = 1.0
                        onClicked:{
                            console.log("Zero clicked")
                            collectionInfo.toZero();
                            tareText.text=0
                        }
                    }
                }
            }

            // 去皮按钮
            Item {
                width: 200; height: 200

                Image {
                    id: tareBtn
                    anchors.centerIn: parent
                    anchors.verticalCenterOffset: 20
                    width: 200; height: 200
                    source: "qrc:/assets/buttonjz.png"
                    smooth: true
                    property real baseScale: 1.0
                    scale: baseScale
                    Behavior on scale { NumberAnimation { duration: 120; easing.type: Easing.OutQuad } }
                    MouseArea {
                        anchors.fill: parent
                        onPressed: tareBtn.baseScale = 0.92
                        onReleased: tareBtn.baseScale = 1.0
                        onClicked:{
                            console.log("Tare clicked")
                            collectionInfo.toTare();
                            tareText.text=weightText.text
                        }
                    }
                }
            }
        }
    }
}
